﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Collections.Generic;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.Utils;
using Newtonsoft.Json;

namespace Ccit.OA.Scheduler
{
    public partial class scheduler_mySch_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
             

                // ViewState["Date"] 时间       ViewState["RangeType"] 日程显示类型：DAY按日显示/WORKWEEK按工作周显示/WEEK按周显示/MONTH按月显示
                ViewState["sQsrq"] = (null != Request.QueryString["sQsrq"]) ? Request.QueryString["sQsrq"].ToString() : "";
                ViewState["sJzrq"] = (null != Request.QueryString["sJzrq"]) ? Request.QueryString["sJzrq"].ToString() : "";
                ViewState["RangeType"] = (null != Request.QueryString["RangeType"]) ? Request.QueryString["RangeType"].ToString() : "";

                lnbAdd.Attributes.Add("onclick", "return doAdd()");
                lnbDel.Attributes.Add("onclick", "return doDel()");
                lnbFul.Attributes.Add("onclick", "return doFul()");
                initPage();
            }
        }

        public void initPage()
        {
            string sDate="", sRangeType, sQsrq, sJzrq;
            sQsrq = ViewState["sQsrq"].ToString().Trim();
            sJzrq = ViewState["sJzrq"].ToString().Trim();
            sRangeType = ViewState["RangeType"].ToString().Trim();

            SchedulerBLL bll = new SchedulerBLL();

            #region 初始化时获取参数设置的样式
            if (sRangeType == "")
            {
                MsSchParam msParam = bll.GetSchParam();
                switch (msParam.ShowDefaultStyle.Trim())
                { 
                    case "1":
                        sRangeType = "DAY";
                        break;
                    case "2":
                        sRangeType = "WORKWEEK";
                        sQsrq = bll.GetFirstWeekDate(DateTime.Today).ToString("yyyy-MM-dd");
                        sJzrq = bll.GetFirstWeekDate(DateTime.Today).AddDays(-2).ToString("yyyy-MM-dd");
                        break;
                    case "3":
                        sRangeType = "WEEK";
                        sQsrq = bll.GetFirstWeekDate(DateTime.Today).ToString("yyyy-MM-dd");
                        sJzrq = bll.GetLastWeekDate(DateTime.Today).ToString("yyyy-MM-dd");
                        break;
                    case "4":
                        sRangeType = "MONTH";
                        sQsrq = DateTime.Today.ToString("yyyy-MM") + "-01";
                        sJzrq = DateTime.Parse(DateTime.Today.AddMonths(1).ToString("yyyy-MM") + "-01").AddDays(-1).ToString("yyy-MM-dd");
                        break;
                    default:
                        sRangeType = "DAY";
                        break;
                }
                ViewState["RangeType"] = sRangeType;
                ViewState["sQsrq"] = sQsrq;
                ViewState["sJzrq"] = sJzrq;
                msParam = null;
            }
            #endregion


            if (sRangeType.ToUpper() == "DAY")
            {
                ImgBack.AlternateText = "上一日";
                ImgForward.AlternateText = "下一日";
            }
            else if (sRangeType.ToUpper() == "WEEK" || sRangeType.ToUpper() == "WORKWEEK")
            {
                ImgBack.AlternateText = "上一周";
                ImgForward.AlternateText = "下一周";
            }
            else if (sRangeType.ToUpper() == "MONTH")
            {
                ImgBack.AlternateText = "上一月";
                ImgForward.AlternateText = "下一月";
            }

            switch (sRangeType)
            {
                case "DAY":
                    if (sQsrq != "")
                    {
                        sDate = sQsrq;
                    }
                    else {
                        sDate = System.DateTime.Now.ToString("yyyy-MM-dd").Trim();  
                        sQsrq = sJzrq =  sDate;
                    }
                    
                    #region 根据时间给日期加颜色
                    lblDate2.Text = Convert.ToDateTime(sDate).ToString("yyyy年MM月dd").Trim() + " " + bll.GetNoOfWeekName(Convert.ToDateTime(sDate).DayOfWeek.ToString());
                    if (Convert.ToDateTime(sDate).Day == System.DateTime.Now.Day) {
                        lblDate2.ForeColor = System.Drawing.Color.Blue;
                    }
                    else if (bll.GetNoOfWeek(Convert.ToDateTime(sDate).DayOfWeek.ToString()) == 0 || bll.GetNoOfWeek(Convert.ToDateTime(sDate).DayOfWeek.ToString()) == 6)
                    {
                        lblDate2.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        lblDate2.ForeColor = System.Drawing.Color.Black;
                    }
                    #endregion
                    break;
                case "WEEK":
                    if (sQsrq != "")
                    {
                        sDate = System.DateTime.Now.Year.ToString().Trim() + "年  第" + bll.WeekOfYear(Convert.ToDateTime(sQsrq)) + "周";
                    }
                    else {
                           sQsrq = System.DateTime.Now.ToString("yyyy-MM-dd").Trim();
                           sJzrq = System.DateTime.Now.AddDays(7).ToString("yyyy-MM-dd").Trim();
                           sDate = System.DateTime.Now.ToString("yyyy-MM-dd").Trim() + "年  第" + bll.WeekOfYear(Convert.ToDateTime(sQsrq)) + "周";
                    }
                    #region 根据时间给日期加颜色
                    lblDate2.Text = sDate + "【" + sQsrq + "  至 " + sJzrq + "】";
                    if (System.DateTime.Now >= Convert.ToDateTime(sQsrq) && System.DateTime.Now <= Convert.ToDateTime(sJzrq))
                    {
                        lblDate2.ForeColor = System.Drawing.Color.Blue;
                    }
                    else {
                        lblDate2.ForeColor = System.Drawing.Color.Black;
                    }
                    #endregion
                    break;
                case "WORKWEEK":
                    if (sQsrq != "") {
                        sDate = System.DateTime.Now.Year.ToString().Trim() + "年  第" + bll.WeekOfYear(Convert.ToDateTime(sQsrq)) + "周";
                    }
                    else
                    {
                        sQsrq = System.DateTime.Now.ToString().Trim();
                        sJzrq = System.DateTime.Now.AddDays(7).ToString("yyyy-MM-dd").Trim();
                        sDate = System.DateTime.Now.ToString("yyyy-MM-dd").Trim() + "年  第" + bll.WeekOfYear(Convert.ToDateTime(sQsrq)) + "周";
                    }
                    #region 根据时间给日期加颜色
                    lblDate2.Text = sDate + "【" + sQsrq + "  至 " + sJzrq + "】";
                    if(System.DateTime.Now >= Convert.ToDateTime(sQsrq) && System.DateTime.Now <= Convert.ToDateTime(sJzrq))
                    {
                        lblDate2.ForeColor = System.Drawing.Color.Blue;
                    }
                    else {
                        lblDate2.ForeColor = System.Drawing.Color.Black;
                    }
                    #endregion
                    break;
                case "MONTH":
                    if (sQsrq != "")
                    {
                        sDate = Convert.ToDateTime(sQsrq).ToString("yyyy-MM").Trim();
                    }
                    else {
                            
                        sDate =  System.DateTime.Now.ToString("yyyy-MM").Trim();
                    }
                    #region 根据时间给日期加颜色
                    lblDate2.Text = Convert.ToDateTime(sDate).ToString("yyyy年 MM 月") + "【" + sQsrq + "  至 " + sJzrq + "】";
                    if (Convert.ToDateTime(sQsrq).Month == System.DateTime.Now.Month)
                    {
                        lblDate2.ForeColor = System.Drawing.Color.Blue;
                    }
                    else {
                        lblDate2.ForeColor = System.Drawing.Color.Black;
                    }
                    #endregion
                    break;
                default :
                    break;
            }
            lblDate.Text = sDate;
            bll = null;

            ViewState["sQsrq"] = sQsrq;
            ViewState["sJzrq"] = sJzrq;
            #region 生成日程表格
            CreateTable(sRangeType, "", sQsrq, sJzrq);
            #endregion
        }

        protected void lnbMonth_Click(object sender, EventArgs e)
        {
            string sQssj, sJzsj;
            string sRangeType;

            sRangeType = "MONTH";
            sQssj = DateTime.Today.ToString("yyyy-MM") + "-01";
            sJzsj = DateTime.Parse(DateTime.Today.AddMonths(1).ToString("yyyy-MM") + "-01").AddDays(-1).ToString("yyy-MM-dd");

            string sparam = "RangeType=" + sRangeType + "&sQsrq=" + sQssj + "&sJzrq=" + sJzsj;
            string encodeparam = Base64Lib.Encode(sparam);
            Response.Redirect(".\\scheduler_mySch_list.aspx?" + encodeparam);
        }

        protected void lnbWeek_Click(object sender, EventArgs e)
        {
            //响应按周按钮
			//需要判断当前日期所在星期数
			
			string sQssj,sJzsj;
			DateTime WeekBeginDate,WeekEndDate;
			string sRangeType;
            sRangeType = "WEEK";
            SchedulerBLL bll = new SchedulerBLL();

            WeekBeginDate = bll.GetFirstWeekDate(DateTime.Today);
            WeekEndDate = bll.GetLastWeekDate(DateTime.Today);
			sQssj=WeekBeginDate.ToString("yyyy-MM-dd");
			sJzsj=WeekEndDate.ToString("yyyy-MM-dd");

            string sparam = "RangeType=" + sRangeType + "&sQsrq=" + sQssj + "&sJzrq=" + sJzsj;
            string encodeparam = Base64Lib.Encode(sparam);
            bll = null;
            Response.Redirect(".\\scheduler_mySch_list.aspx?" + encodeparam);
		}

        protected void lnbDay_Click(object sender, EventArgs e)
        {
            //响应按日按钮
			string sRangeType;
			sRangeType="DAY";

            string sparam = "RangeType=" + sRangeType;
            string encodeparam = Base64Lib.Encode(sparam);
            Response.Redirect(".\\scheduler_mySch_list.aspx?" + encodeparam);

        }

        protected void lnbWordWeek_Click(object sender, EventArgs e)
        {
            //响应按工作周按钮
            //需要判断当前日期所在星期数

            string sQssj, sJzsj;
            DateTime WeekBeginDate, WeekEndDate;
            string sRangeType;
            sRangeType = "WORKWEEK";

            SchedulerBLL bll = new SchedulerBLL();

            WeekBeginDate = bll.GetFirstWeekDate(DateTime.Today);
            WeekEndDate = bll.GetLastWeekDate(DateTime.Today);
            sQssj = WeekBeginDate.ToString("yyyy-MM-dd");
            sJzsj = WeekEndDate.AddDays(-2).ToString("yyyy-MM-dd");

            string sparam = "RangeType=" + sRangeType + "&sQsrq=" + sQssj + "&sJzrq=" + sJzsj;
            string encodeparam = Base64Lib.Encode(sparam);
            bll = null;
            Response.Redirect(".\\scheduler_mySch_list.aspx?" + encodeparam);
        }

        protected void ImgBack_Click(object sender, ImageClickEventArgs e)
        {
            doTurnPage("BACK");
        }

        protected void ImgForward_Click(object sender, ImageClickEventArgs e)
        {
            doTurnPage("FORWARD");
        }

        #region server function
        private void CreateTable(string sRangeType, string RCLX, string Qsrq, string Jzrq)
        {
            if (sRangeType == "DAY")
            {
                CreateDayTable(Qsrq, Jzrq, sRangeType);
            }
            else if (sRangeType == "WEEK" || sRangeType == "WORKWEEK")
            {
                Table1.Height = "100";
                CreateWeekTable(Qsrq, Jzrq, sRangeType);
            }
            else if (sRangeType == "MONTH")
            {
                CreateMonthTable(Qsrq, Jzrq, sRangeType);
            }
        }

        #region 根据起始时间以及查看的日程类型 查看表格
        private void CreateDayTable(string Qsrq, string Jzrq, string sRangeType)
        {
            LoginUser loginUser = Session["LogUserInfo"] as LoginUser;
            
            string sUserId, BmId, Qssj, Jzsj;
            string sHtmlOut;
            sUserId = loginUser.UserId;
            BmId = "ALL";
            Qssj = Qsrq + " 00:00";
            Jzsj = Jzrq + " 23:59";


            sRangeType = sRangeType.ToUpper();


            sHtmlOut = "";
           
            switch (DateTime.Parse(Qsrq).DayOfWeek)
            {
                case DayOfWeek.Saturday:
                case DayOfWeek.Sunday:
                    lblDate.ForeColor = System.Drawing.Color.Red;
                    break;
                default:
                    if (Qsrq == DateLib.FormatDate(System.DateTime.Now.ToString().Trim(),"yyyy-mm-dd"))
                        lblDate.ForeColor = System.Drawing.Color.Blue;
                    else
                        lblDate.ForeColor = System.Drawing.Color.Black;
                    break;
            }

            //修改内容
            sHtmlOut = GetCalendarMemory(Qssj, Jzsj, "", sUserId, sRangeType,"");

            HtmlTableRow tempRow1 = new HtmlTableRow();
            HtmlTableCell tempCell1 = new HtmlTableCell();

            tempCell1.InnerHtml = sHtmlOut;
            tempCell1.VAlign = "Top";
            tempRow1.Cells.Add(tempCell1);
            tblMain.Rows.Add(tempRow1);



        }

        private void CreateWeekTable(string Qsrq, string Jzrq, string sRangeType)
        {
            LoginUser loginUser = Session["LogUserInfo"] as LoginUser;
            string BmId, Qssj, Jzsj;

            Qssj = "";
            Jzsj = "";
            BmId = "ALL";
            sRangeType = sRangeType.ToUpper();

            string sStartDate = DateLib.FormatDate(Qsrq, "yyyy-mm-dd");
            string sEndDate = DateLib.FormatDate(Jzrq, "yyyy-mm-dd");

            DateTime dtStart = Convert.ToDateTime(sStartDate);
            DateTime dtEnd = Convert.ToDateTime(sEndDate);
            DateTime dtNow = System.DateTime.Now;

            for (int i = 1; i < 4; ++i)
            {
                HtmlTableRow titleRow = new HtmlTableRow();
                HtmlTableRow contentRow = new HtmlTableRow();
                int iCount = i+2 ;
                
                #region 左边日程信息
                HtmlTableCell tempCell1 = new HtmlTableCell();
                tempCell1.VAlign = "Top";
                tempCell1.Width = "25%";
                tempCell1.Height = "30%";
                tempCell1.Attributes["Style"] = "margin-top: 0px;border-style: solid;border-width: 1px;border-left:0px; border-bottom:0px;border-color:#9C9C9C;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;";
                Qssj = DateTime.Parse(Qsrq).AddDays(i-1).ToString("yyyy-MM-dd") + " 00:00";
                Jzsj = DateTime.Parse(Qsrq).AddDays(i-1).ToString("yyyy-MM-dd") + " 23:59";
                tempCell1.InnerHtml = GetCalendarMemory(Qssj, Jzsj, BmId, loginUser.UserId, sRangeType,"");
                contentRow.Cells.Add(tempCell1);
                #endregion

                #region 右边日程信息
                HtmlTableCell tempCell2 = new HtmlTableCell();
                tempCell2.VAlign = "Top";
                tempCell2.Width = "25%";
                tempCell2.Height = "30%";
                tempCell2.Attributes["Style"] = "margin-top: 0px;border-style: solid;border-width: 1px;border-left:0px; border-bottom:0px;border-color:#9C9C9C;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;";

                if (iCount != 5)
                {
                    if (iCount == 4)
                    {
                        if (sRangeType != "WEEK")
                        {
                            tempCell2.RowSpan = 2;
                        }
                    }
                    Qssj = DateTime.Parse(Qsrq).AddDays(iCount).ToString("yyyy-MM-dd") + " 00:00";
                    Jzsj = DateTime.Parse(Qsrq).AddDays(iCount).ToString("yyyy-MM-dd") + " 23:59";
                    tempCell2.InnerHtml = GetCalendarMemory(Qssj, Jzsj, "", loginUser.UserId, sRangeType, "");
                    contentRow.Cells.Add(tempCell2);
                }
                else
                {
                    #region 判断若是工作日时 不显示 周六与周日
                    if (sRangeType == "WEEK")
                    {
                        HtmlTable WorkweekTable = new HtmlTable();
                        HtmlTableRow WorkweekRow;
                        HtmlTableCell tempCell3;
                        for (int j = 5; j < 7; ++j)
                        {
                            WorkweekRow = new HtmlTableRow();
                            tempCell3 = new HtmlTableCell();
                            tempCell3.VAlign = "Top";
                            tempCell3.Width = "25%";
                            Qssj = DateTime.Parse(Qsrq).AddDays(j).ToString("yyyy-MM-dd") + " 00:00";
                            Jzsj = DateTime.Parse(Qsrq).AddDays(j).ToString("yyyy-MM-dd") + " 23:59";
                            tempCell3.InnerHtml = GetCalendarMemory(Qssj, Jzsj, "", "", sRangeType,"50");
                            WorkweekRow.Cells.Add(tempCell3);
                            WorkweekTable.Rows.Add(WorkweekRow);
                        }
                        tempCell2.Controls.Add(WorkweekTable);
                        contentRow.Cells.Add(tempCell2);
                    }
                    else
                    {
                        tempCell2.Attributes["Style"] = "margin-top: 0px;border-style: solid;border-width: 1px;border-left:0px; border-bottom:0px;border-color:#9C9C9C;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;";
                        tempCell2.InnerHtml = "&nbsp;";
                    }
                    #endregion
                }
                #endregion

                tblMain.Height = "100%";
                tblMain.Rows.Add(contentRow);
                Table1.Height = "85%";
            }

        }

        private void CreateMonthTable(string Qsrq, string Jzrq, string sRangeType)
        {
            LoginUser loginUser = Session["LogUserInfo"] as LoginUser;
            SchedulerBLL bll = new SchedulerBLL();
            string BmId, Qssj, Jzsj;

            int i, j, k, beginFlag;
            HtmlTableRow tempRow = new HtmlTableRow();

            k = 1;

            Qssj = "";
            Jzsj = "";
            BmId = "All";
            sRangeType = sRangeType.ToUpper();


            string sStartDate = DateLib.FormatDate(Qsrq, "yyyy-mm-dd");
            string sEndDate = DateLib.FormatDate(Jzrq, "yyyy-mm-dd");

            DateTime dtStart = Convert.ToDateTime(sStartDate);
            DateTime dtEnd = Convert.ToDateTime(sEndDate);
            DateTime dtNow = System.DateTime.Now;

            beginFlag = bll.GetNoOfWeek(DateTime.Parse(Qsrq).DayOfWeek.ToString());
            if (beginFlag == 0)
            { beginFlag = 7; }

            for (i = 1; i < 8; i++)
            {
                //生成月日历表头
                HtmlTableCell tempCell = new HtmlTableCell();
                tempCell.InnerHtml = "星期" + bll.eNoToCno(i);// +"(" +DateTime.Parse(Qsrq).AddDays(i-1).ToString("yyyy-MM-dd") + ")";
                tempCell.Attributes["align"] = "center";
                tempCell.Attributes["Valign"] = "TOP";
                tempCell.Style["font"] = "bolder";
                tempRow.Cells.Add(tempCell);

            }
            tempRow.Attributes["CLASS"] = "row4";
            tblMain.Rows.Add(tempRow);

            string sFirstDay = DateLib.FormatDate(sStartDate, "yyyy-mm") + "-01";
            int iMonth = Convert.ToDateTime(sStartDate).Month;
            int iRowCount = 5;
            switch (iMonth)
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    //如果本月1号是周六或者周日,那么需要显示6行
                    DateTime dtLarge = Convert.ToDateTime(sFirstDay);
                    if (dtLarge.DayOfWeek == DayOfWeek.Saturday || dtLarge.DayOfWeek == DayOfWeek.Sunday)
                    {
                        iRowCount = 6;
                    }
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    //如果本月1号是周日,那么需要显示6行
                    DateTime dtSmall = Convert.ToDateTime(sFirstDay);
                    if (dtSmall.DayOfWeek == DayOfWeek.Sunday)
                    {
                        iRowCount = 6;
                    }
                    break;
                case 2:
                    DateTime dt = Convert.ToDateTime(sFirstDay);
                    //如果是闰年,那么显示5行,否则,如果本月1号是周一,那么显示4行
                    if (!DateTime.IsLeapYear(dt.Year))
                    {
                        if (dt.DayOfWeek == DayOfWeek.Monday)
                        {
                            iRowCount = 4;
                        }
                    }
                    break;
                default:
                    break;
            }

            for (j = 1; j <= iRowCount; j++)
            {
                HtmlTableRow tempRow1 = new HtmlTableRow();
                for (i = 1; i < 8; i++)
                {
                    //生成月日历内容

                    HtmlTableCell tempCell1 = new HtmlTableCell();
                    if (k >= (beginFlag) && DateTime.Parse(Qsrq).AddDays(k - beginFlag) <= DateTime.Parse(Jzrq))
                    {
                        Qssj = DateTime.Parse(Qsrq).AddDays(k - beginFlag).ToString("yyyy-MM-dd") + " 00:00";
                        Jzsj = DateTime.Parse(Qsrq).AddDays(k - beginFlag).ToString("yyyy-MM-dd") + " 23:59";

                        tempCell1.InnerHtml = GetCalendarMemory(Qssj, Jzsj, BmId, loginUser.UserId,sRangeType,"");
                        tempCell1.Width = "14.3%";
                        tempCell1.Height = "100";
                        tempCell1.VAlign = "Top";

                    }
                    else
                    { tempCell1.InnerHtml = "&nbsp;"; }
                    tempCell1.Height = "100";
                    tempCell1.Width = "14.3%";

                    if (i < 7)
                    {
                        tempCell1.Attributes["Style"] = "margin-top: 0px;border-style: solid;border-width: 1px;border-left:0px; border-bottom:0px;border-color:#9C9C9C;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;";
                    }
                    else
                    {
                        tempCell1.Attributes["Style"] = "margin-top: 0px;border-style: solid;border-width: 1px;border-left:0px; border-bottom:0px;border-right:0px; border-color:#9C9C9C;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;";
                    }
                    tempRow1.Cells.Add(tempCell1);

                    k = k + 1;
                }
                tblMain.Rows.Add(tempRow1);

            }
        }

        #endregion

        private string GetCalendarMemory(string Qssj, string Jzsj, string BmId,string UserId, string Type,string sHeight)
        {
            //返回时间范围内的日程内容
            string sHtmlOut;
            string sUserId;
            string sRangeType, sQsrq, sJzrq;
            string QueryStr;

            SchedulerBLL bll = new SchedulerBLL();
            LoginUser loginUser = Session["LogUserInfo"] as LoginUser;

            if (sHeight == "")
            { 
               sHeight = "100";
            }

            sRangeType = ViewState["RangeType"].ToString();
            sQsrq = Qssj;
            sJzrq = Jzsj;

            QueryStr = "&RangeType=" + sRangeType + "&Qsrq=" + sQsrq + "&Jzrq=" + sJzrq;

            sHtmlOut = "";
            sUserId = UserId.Trim();

            List<MsScheduler> MsList = bll.GetSchedulers("").Where(s => (s.ProxyId == sUserId || s.cjuserId == sUserId) && Convert.ToDateTime(s.BeginTime) >= Convert.ToDateTime(sQsrq) && Convert.ToDateTime(s.EndTime) <= Convert.ToDateTime(sJzrq)).ToList<MsScheduler>();
            DataSet dSet = new DataSet();
            string sDate = DateLib.FormatDate(Qssj, "yyyy-mm-dd");

            string sWeekName = "&nbsp;&nbsp;" + bll.GetNoOfWeekName(Convert.ToDateTime(sDate).DayOfWeek.ToString().Trim());
            if (sDate == DateLib.FormatDate(System.DateTime.Now.ToString(),"yyyy-mm-dd"))
            {
                sHtmlOut = sHtmlOut + "<table style='height:" + sHeight + ";table-layout:fixed;' valign=top width=100%><tr valign='top'><td bgcolor='#00CC99' valign='top' nowrap style='height:20' width=100%>";
                sHtmlOut = sHtmlOut + DateLib.FormatDate(Qssj, "yyyy-mm-dd");
                if (Type == "WEEK" || Type == "WORKWEEK" || Type == "DAY")
                    sHtmlOut += sWeekName;
                    
                sHtmlOut += "<font color=red>(今天)</font>" + "</td></tr>";
            }
            else
            {
                sHtmlOut = sHtmlOut + "<table style='height:" + sHeight + "' valign=top width=100%><tr valign='top'><td bgcolor='E7F3F7' valign='top' nowrap style='height:20' width=100%>";
                sHtmlOut = sHtmlOut + DateLib.FormatDate(Qssj, "yyyy-mm-dd");
                if (Type == "WEEK" || Type == "WORKWEEK" || Type == "DAY")
                    sHtmlOut += sWeekName;
                sHtmlOut += "</td></tr>";
            }
            //判断是否是当前日期
            sHtmlOut = sHtmlOut + "<tr><td valign=top style='overflow:hidden;text-overflow:ellipsis;'>";
            if (MsList.Count > 0)
            {
                int len = MsList.Count;
                for (int i = 0; i < len; i++)
                {
                    sHtmlOut = sHtmlOut + "<div style='background-color: " + MsList[i].Description.Replace("@", "#") + "'><input type='checkbox' onclick=doOptions('" + MsList[i].SchId + "') id='checkbox" + MsList[i].SchId + "' value='" + MsList[i].SchId + "' name='checkDel'>";
                    string sparam = "SchId=" + MsList[i].SchId;
                    string encodeparam = Base64Lib.Encode(sparam);
                    sHtmlOut = sHtmlOut + "<a title='日程内容:  " + MsList[i].schConvert + "' href=\"javascript:doedit('" + encodeparam + "');\">";
                    sHtmlOut += "(" + MsList[i].BeginTime.Split(' ')[1].Trim() + "~" + MsList[i].EndTime.Split(' ')[1].Trim() + ")";
                    sHtmlOut = sHtmlOut + MsList[i].Subject + "</a>";
                    if (MsList[i].SchFlag == "1")
                    {
                        sHtmlOut = sHtmlOut + "<font color='Blue' title='代理日程' alt='代理日程'>▲</font>";
                    }
                    if (MsList[i].SchAttr == "1")
                    {
                        sHtmlOut = sHtmlOut + "<font color='Blue' title='私人日程' alt='私人日程'>★</font>";
                    }
                    if (MsList[i].CompState == "1")
                    {
                        sHtmlOut = sHtmlOut + "<font color='GREEN' title='已完成' alt='已完成'>√</font>";
                    }
                    
                    sHtmlOut += "</div>";
                }

            }

            sHtmlOut = sHtmlOut + "</td></tr></table>";
            bll = null;
            return sHtmlOut;
        }


        private void doTurnPage(string TurnPageType)
        {
            string QSRQ_old, JZRQ_old, QSRQ_new, JZRQ_new;
            QSRQ_old = ViewState["sQsrq"].ToString();
            JZRQ_old = ViewState["sJzrq"].ToString();
            QSRQ_new = "";
            JZRQ_new = "";

            string sRangeType = ViewState["RangeType"].ToString().Trim().ToUpper();


            if (TurnPageType == "FORWARD") //下一日，下一周，下一月
            {
                if (sRangeType == "DAY")
                {
                    QSRQ_new = DateTime.Parse(QSRQ_old).AddDays(1).ToString("yyyy-MM-dd");
                    JZRQ_new = DateTime.Parse(JZRQ_old).AddDays(1).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "WEEK")
                {
                    QSRQ_new = DateTime.Parse(JZRQ_old).AddDays(1).ToString("yyyy-MM-dd");
                    JZRQ_new = DateTime.Parse(JZRQ_old).AddDays(7).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "WORKWEEK")
                {
                    QSRQ_new = DateTime.Parse(JZRQ_old).AddDays(3).ToString("yyyy-MM-dd");
                    JZRQ_new = DateTime.Parse(JZRQ_old).AddDays(7).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "MONTH")
                {
                    QSRQ_new = DateTime.Parse(JZRQ_old).AddDays(1).ToString("yyyy-MM-dd");
                    JZRQ_new = DateTime.Parse(DateTime.Parse(JZRQ_old).AddMonths(2).ToString("yyyy-MM") + "-01").AddDays(-1).ToString("yyyy-MM-dd");
                }
            }
            else if (TurnPageType == "BACK") //上一日，上一周，上一月
            {
                if (sRangeType == "DAY")
                {
                    QSRQ_new = DateTime.Parse(QSRQ_old).AddDays(-1).ToString("yyyy-MM-dd");
                    JZRQ_new = DateTime.Parse(JZRQ_old).AddDays(-1).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "WEEK")
                {
                    JZRQ_new = DateTime.Parse(QSRQ_old).AddDays(-1).ToString("yyyy-MM-dd");
                    QSRQ_new = DateTime.Parse(QSRQ_old).AddDays(-7).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "WORKWEEK")
                {
                    JZRQ_new = DateTime.Parse(QSRQ_old).AddDays(-3).ToString("yyyy-MM-dd");
                    QSRQ_new = DateTime.Parse(QSRQ_old).AddDays(-7).ToString("yyyy-MM-dd");
                }
                else if (sRangeType == "MONTH")
                {
                    JZRQ_new = DateTime.Parse(QSRQ_old).AddDays(-1).ToString("yyyy-MM-dd");
                    QSRQ_new = DateTime.Parse(JZRQ_old).AddMonths(-1).ToString("yyyy-MM") + "-01";
                }

            }

            string sparam = "RangeType=" + sRangeType + "&sQsrq=" + QSRQ_new + "&sJzrq=" + JZRQ_new;
            string encodeparam = Base64Lib.Encode(sparam);
            Response.Redirect(".\\scheduler_mySch_list.aspx?" + encodeparam);
        }
        #endregion

        protected void lnbDel_Click(object sender, EventArgs e)
        {
            if (hidVar.Value.Trim() != "")
            {
                MsScheduler Ms = new MsScheduler();
                SchedulerBLL bll = new SchedulerBLL();
                Ms.SchId = hidVar.Value.Trim(',');
                if (bll.DelSch(Ms))
                {
                   // Response.Write("<script>alert('删除！');</script>");
                }
                hidVar.Value = "";
                bll = null;
                initPage();
            }
            else {
                Response.Write("<script>alert('删除失败,请与管理员联系！');</script>");
            }
        }

        protected void lnbFul_Click(object sender, EventArgs e)
        {
            if (hidVar.Value.Trim() != "")
            {
                MsScheduler Ms = new MsScheduler();
                SchedulerBLL bll = new SchedulerBLL();
                Ms.SchId = hidVar.Value.Trim(',');
                if (bll.UpdateFulSch(Ms))
                {
                }
                else
                {
                    Response.Write("<script>alert('日程置为完成状态操作失败,请与管理员联系!');</script>");
                }
                hidVar.Value = "";
                bll = null;
                Ms = null;
                initPage();
            }
        }



    }
}
